package com.siysoft.tc.remind.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.siysoft.tc.remind.service.IRemindService;
import com.siysoft.util.COMMON;
import com.tc.base.controller.BaseController;

@Controller
@RequestMapping(value = "/app/remind")
public class RemindController extends BaseController{
	@Autowired
	IRemindService remindService;
	
	/**
	 * 
	 * @param request
	 * @param response
	 */
	
	@RequestMapping(value = "/hasNewRemind")
	public void hasNewRemind(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("type"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer user_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer type = Integer.valueOf(request.getParameter("type").toString());
			
			Boolean result = remindService.hasNewRemind(user_id, type);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result?1:0);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	@RequestMapping(value = "/addNewRemind")
	public void addNewRemind(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if(  COMMON.isnull(request.getParameter("type"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer type,data_id = 0,user_id = 0;
			type = Integer.valueOf(request.getParameter("type").toString());
			if(request.getParameter("data_id") != null)
				data_id = Integer.valueOf((request.getParameter("data_id")));
			if(request.getParameter("user_id") != null)
				user_id = Integer.valueOf((request.getParameter("user_id")));
			
			Boolean result = remindService.addNewRemind(type,data_id,user_id);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result?1:0);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	@RequestMapping(value = "/cancelRemind")
	public void cancelRemind(HttpServletRequest request,
			HttpServletResponse response){
		try{
			if( COMMON.isnull(request.getParameter("user_id"))
					|| COMMON.isnull(request.getParameter("type"))
					)
			{
				this.responseFail(response, -32602, "参数无效", "指定参数不符合服务接口定义");
				return ;
			}
			Integer data_id = Integer.valueOf(request.getParameter("user_id").toString());
			Integer type = Integer.valueOf(request.getParameter("type").toString());
			
			Boolean result = remindService.cancelRemind(data_id, type);
			
			JSONObject obj = new JSONObject();
			obj.accumulate("result", result?1:0);
			String format_json = this.FormatJson(0, "", Object2Json(obj));
			this.responseSuccess(response, format_json, 0);
			return;
		}
		catch(Exception e){
			e.printStackTrace();
			this.responseFail(response, -32602, "服务器有点忙，请过会重试", "");
			return ;
		}
	}
	
	
}
